package net.oschina.simpleplus.ser.impl;

import java.util.UUID;

import org.apache.shiro.crypto.hash.SimpleHash;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import net.oschina.simpleplus.dao.UserDao;
import net.oschina.simpleplus.entity.User;
import net.oschina.simpleplus.ser.UserSer;

@Service
public class UserSerImpl implements UserSer{
	
	@Autowired
	private UserDao userDao;

	@Override
	public void login(String email, String passwd) {
		User user = userDao.findUserByEmail(email);
		String hex = new SimpleHash("md5", passwd, email +"$sns$"+user.getSalt(), 2).toHex();
		if(!hex.equals(user.getPassword())){
			
		}
	}
	
	
	@Override
	public void reg(String email, String passwd) {
		User user = new User();
		user.setEmail(email);
		user.setSalt(UUID.randomUUID().toString().replaceAll("-", ""));
		user.setPassword(new SimpleHash("md5", passwd, email +"$sns$"+user.getSalt(), 2).toHex());
		user.setNickName(email.substring(0, email.indexOf("@")));
		user.setHeadImg("/defaul/head.png");
		userDao.insertNewUser(user);
	}

}
